package gunfire.actions;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.ui.panels.EnergyPanel;
import gunfire.GunfireMod;

public class FireDragonAction extends AbstractGameAction {

    private AbstractPlayer p;
    private AbstractMonster m;
    private boolean freeToPlayOnce;
    private int energyOnUse;
    private int damage;
    private boolean upgraded;

    public FireDragonAction(AbstractPlayer p, AbstractMonster m, boolean freeToPlayOnce, int energyOnUse, int damage, boolean upgraded){
        this.m = m;
        this.p = p;
        this.freeToPlayOnce = freeToPlayOnce;
        this.energyOnUse = energyOnUse;
        this.damage = damage;
        this.upgraded = upgraded;
    }

    @Override
    public void update() {
        int effect = EnergyPanel.totalCount;
        if (this.energyOnUse != -1) {
            effect = this.energyOnUse;
        }

        if (this.p.hasRelic("Chemical X")) {
            effect += 2;
            this.p.getRelic("Chemical X").flash();
        }

        if(this.upgraded){
            effect++;
        }

        if (effect > 0) {
            //必须是反向top，否则与腐蚀结合无法清除缓慢
            this.addToTop(new ElementalEffectAction(m, p, effect, GunfireMod.ElementalEffect.Burning));
            for (int i = 0; i < effect; i++) {
                this.addToTop(new DamageAction(m, new DamageInfo(p, this.damage, GunfireMod.ELEMENT_DAMAGE), AbstractGameAction.AttackEffect.FIRE));
            }

            if (!this.freeToPlayOnce) {
                this.p.energy.use(EnergyPanel.totalCount);
            }
        }

        this.isDone = true;
    }
}
